package com.wikilife.index.model;

import android.graphics.Color;

import com.oklib.utils.helper.RxUtil;
import com.wikilife.index.contract.IndexContract;

import java.util.ArrayList;
import java.util.List;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by Damon.Han on 2017/2/21 0021.
 *
 * @author Damon
 */

public class IndexModel implements IndexContract.Model {
    /**
     * 首页顶部banner
     *
     * @return
     */
    @Override
    public Observable<List<IndexBanner>> getBanner() {
        List<IndexBanner> list = new ArrayList<>();
        IndexBanner indexBanner = null;
        indexBanner = new IndexBanner();
        indexBanner.title = "给最爱的人";
        indexBanner.url = "http://dealer0.autoimg.cn/dl/10982/newsimg/130364690780019046.jpg";
        list.add(indexBanner);
        Observable<List<IndexBanner>> observable = Observable.create(new Observable.OnSubscribe<List<IndexBanner>>() {
            @Override
            public void call(Subscriber<? super List<IndexBanner>> subscriber) {
                subscriber.onNext(list);
                subscriber.onCompleted();
            }
        }).compose(RxUtil.<List<IndexBanner>>rxSchedulerHelper());
        return observable;
    }

    /**
     * 首页顶部入口items
     *
     * @return
     */
    @Override
    public Observable<IndexEntrance> getEntrance() {
        return null;
    }

    /**
     * 首页推荐信息
     *
     * @return
     */
    @Override
    public Observable<List<IndexRecommend>> getRecommends() {
        List<IndexRecommend> list = new ArrayList<>();
        IndexRecommend indexBanner = null;
        indexBanner = new IndexRecommend();
        indexBanner.title = "天天满减";
        indexBanner.subTitle = "每天有新优惠";
        indexBanner.colorId = getRandomColor();
        indexBanner.url = "http://dealer0.autoimg.cn/dl/10982/newsimg/130364690780019046.jpg";
        list.add(indexBanner);
        Observable<List<IndexRecommend>> observable = Observable.create(new Observable.OnSubscribe<List<IndexRecommend>>() {
            @Override
            public void call(Subscriber<? super List<IndexRecommend>> subscriber) {
                subscriber.onNext(list);
                subscriber.onCompleted();
            }
        }).compose(RxUtil.<List<IndexRecommend>>rxSchedulerHelper());
        return observable;
    }

    private int getRandomColor() {
        String hex = Integer.toHexString(-16777216);
        return Color.parseColor("#" + hex);
    }
}
